<?php

/*
Plugin Name: WPS3Slider1.3Dev
Plugin URI: http://www.kevinbradwick.co.uk/2010/06/wps3slider-plugin-for-wordpress/ 
Description: A plugin that integrates the jQuery s3slider plugin
Version: 1.2
Author: Kevin Bradwick
Author URI: http://www.kevinbradwick.co.uk
Licence: GPL2

Copyright 2010 Kevin Bradwick  (email : kbradwick@gmail.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as 
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

ini_set('display_errors','on');


/**
 * Define constants
 */
defined('WP_PLUGIN_URL') || define(WP_PLUGIN_URL, WP_CONTENT_URL . '/plugins', true);


/**
 * Register plugin activation
 */
function wps3_activation()
{
	global $wpdb;
	$schema = file_get_contents(dirname(__FILE__).'/schema.sql');
	$schema = str_replace('{PREFIX}', $wpdb->prefix, $schema);

    $queries = explode('-NEXT-', $schema);

    foreach($queries as $sql) {
        $wpdb->query(trim($sql));
    }
    
}
register_activation_hook(__FILE__, 'wps3_activation');


/**
 * The menu builder
 */
function wps3_admin_menus()
{
    add_media_page('WPS3Slider', 'WPS3Slider', 'manage_options', 'wps3-top', 'wps3_menu');
}


function wps3_menu()
{
	
	require_once('wordpresspdk/wp_pdk_form.php');
	$form = new WordPress_PDK_Form('add-gallery');
	$form->validators = array(
		array('gallery_name','length','min'=>2,'max'=>6,'message'=>'Gallery name is too short')
	);
	
	if(isset($_POST['add-gallery'])) {
		$form->attributes = $_POST['add-gallery'];
		if($form->validate()) {
			echo 'success';
			echo $form->gallery_name;
		} else {
			echo 'failure';
		}
	}
	?>
    <div class="wrap">
      <h2>WPS3Slider</h2>
      <?php echo $form->beginForm(); ?>
      <p><?php echo $form->label('Gallery Name', 'gallery_name') . $form->textField('gallery_name'); ?></p>
      <p><?php echo $form->error('gallery_name'); ?></p>
      <p><?php echo $form->submitButton(); ?></p>
      <?php echo $form->endForm(); ?>
    </div>
    <?php
}


/***
 * admin actions
 */
add_action('admin_menu', 'wps3_admin_menus');
?>